package xyz.thoughtset.viewer.models.openai;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.model.Model;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.ai.zhipuai.ZhiPuAiChatOptions;
import org.springframework.ai.zhipuai.ZhiPuAiImageModel;
import org.springframework.ai.zhipuai.ZhiPuAiImageOptions;
import org.springframework.ai.zhipuai.api.ZhiPuAiApi;
import org.springframework.ai.zhipuai.api.ZhiPuAiImageApi;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import xyz.thoughtset.viewer.common.ai.model.entity.AiNode;
import xyz.thoughtset.viewer.common.ai.model.entity.ModelParam;
import xyz.thoughtset.viewer.common.ai.model.factory.DefaultModelBuilder;
import xyz.thoughtset.viewer.common.ai.model.factory.ModelBuilder;

import java.util.List;

@Component
public class ZhipuImageBuilder extends ModelBuilder {
    public ZhipuImageBuilder() {
        super("ZhipuAI", List.of("CogView-4","Cogview-3-Flash" ));
    }


    @Override
    public Model buildMode(AiNode node, ModelParam modelParam) {
        ZhiPuAiImageOptions.Builder builder = ZhiPuAiImageOptions.builder()
                .model(modelParam.getModel());
        ZhiPuAiImageOptions options = builder.build();
        ZhiPuAiImageApi api = new ZhiPuAiImageApi(node.getBaseUrl(), node.getApiKey(), RestClient.builder());
        ZhiPuAiImageModel model = new ZhiPuAiImageModel(api, options, RetryUtils.DEFAULT_RETRY_TEMPLATE);
//        ChatModel chatModel = ZhiPuAiChatModel.builder()
//                .defaultOptions(options)
//                .openAiApi(api)
//                .build();
        return model;
    }
}
